package model.commands.booleans;

import java.util.List;
import model.Environment;
import model.SyntaxErrorException;
import model.commands.Command;


/**
 * Name:
 * EQUAL? value1 value2
 * EQUALP value1 value2
 * 
 * Description:
 * returns 1 if value1 and value2 are equal, otherwise 0
 * 
 * @author JLongley
 * @author Erick Gonzalez
 */
public class EqualCommand extends Command {

    @Override
    public int evaluate(Environment e) throws SyntaxErrorException {
        List<Command> myArguments = getArguments();
        //evaluates to true if all arguments equal the first argument
        boolean myEqual = true;
        int firstArg = myArguments.get(0).evaluate(e);
        for (int i = 1; i < myArguments.size(); i++) {
            myEqual = myEqual && firstArg == myArguments.get(i).evaluate(e);
        }        
        return myEqual ? 1 : 0;
    }
}
